﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Text;

public partial class bgDate_DayValue : System.Web.UI.Page
{
    string id;
    string qsrq;
    string jsrq;
    string unit;
    string time;
    string repName;

    BLLData da = new BLLData();
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            repName = HttpUtility.UrlDecode(Request.QueryString["repName"]);
            unit = Request.QueryString["uint"];
            time = Request.QueryString["time"];
            id = Request.QueryString["IDKEY"];

            this.hID.Value = id;
            this.hTime.Value = time;
            this.jz.Value = unit;

            DateTime dt = DateTime.Now;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            if (DateTime.Parse(time) <= dt)
            {
                DataRow dr = da.RetDataRowByID(id);

                string value = da.RetValue(dr["小时点"].ToString(), unit, dr["参数类型"].ToString(), qsrq, jsrq);

                this.zbType.Value = dr["参数类型"].ToString();

                sb.Append("<tr>");

                sb.AppendFormat("<td align='center' id ='" + dr["参数名"] + "'>{0}</td>", dr["参数名"]);

                sb.AppendFormat("<td align='center'>{0}</td>", dr["日点"]);

                sb.AppendFormat("<td align='center'>{0}</td>", qsrq);

                if (value == "没有记录")
                    sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue0\" value='{0}' class=\"nvinput\" /></td>", "0");
                else
                    sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue0\" value='{0}' class=\"nvinput\" /></td>", value);

                sb.Append("</tr>");

                this.show.InnerHtml = sb.ToString();
            }
            else
            {
                Jscript.Alert("请选择正确日期！");
                this.Response.Write("<script language=javascript>window.close();</script>");
            }
        }
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string id = this.hID.Value;
        string unit = this.jz.Value;
        string time = this.hTime.Value;
        string value = this.Hidden1.Value;
        string zbType = this.zbType.Value;

        bool flag = da.RetIsTrueToSaveDay(id, unit, time, zbType, value);

        if (flag == true)
            Jscript.AlertAndCloseWindow("保存成功!");
        else
            Jscript.Alert("保存失败!");
    }
}
